package sec_pages;


import org.openqa.selenium.WebElement;
import utils.Log4Test;

import static org.testng.Assert.assertTrue;

public class SonyXperiaZ2D6502BlackPage extends SecGeneralPage {

    String parentWindowId;


    public void clickButtonBuy() {

        waitForPageLoaded(webDriver);

        parentWindowId = webDriver.getWindowHandle();

        elementIsLocated(getLocator("buttonBuy")).click();

        Log4Test.info("Press Button Buy ");

    }


    public WebElement verifyAddItemRecycleNote() {

        Log4Test.info("Verify that Вы добавили товар в корзину appeared in the recycle ");


        return elementIsLocated(getLocator("popUpRecycle"));
    }

    public WebElement verifyItemRecycle() {

        Log4Test.info("Verify that Sony Xperia Z2 D6502 Black i appeared in the recycle ");


        return elementIsLocated(getLocator("recycleSonyXperiaZ2D6502"));
    }

    public void cancelItemAndVerify(String recycleEmpty) {

        elementIsLocated(getLocator("cancelBuy")).click();

        waitForPageLoaded(webDriver);

        Log4Test.info("Click delete item ");

        waitForPageLoaded(webDriver);

        elementIsLocated(getLocator("popupCloseButton")).click();

        elementIsLocated(getLocator("popupCloseButton")).click();

        waitForPageLoaded(webDriver);

        assertTrue(elementIsLocated(getLocator("recycleNotePage")).getText().toString().contains(recycleEmpty));

        Log4Test.info("Recycle empty ");
    }

    public void signOut() {

        Log4Test.info(elementIsLocated(getLocator("signOutLink")).getText().toString());

        elementIsLocated(getLocator("signOutLink")).click();

        waitForPageLoaded(webDriver);

        Log4Test.info("SignOut ");
    }

    public WebElement verifySuccessfulLogout() {

        Log4Test.info("Verify successful SignOut  ");

        Log4Test.info(elementIsLocated(getLocator("linkEnterToShop")).getText().toString());

        return elementIsLocated(getLocator("linkEnterToShop"));
    }
}
